#ifndef _FRAMEBUFFER
#define _FRAMEBUFFER

// INCLUDES --------------------------------------------------------------------
#include "Base.h"
#include "Vector4.h"

// DEFINES ---------------------------------------------------------------------

// ProcessingType's

// [for every line -> for every pixel of that line], top-to-bottom
#define LINE  0

/* for every block: [for every line -> for every pixel of that line], top-to-bottom
   -> needs: x,y of block, u*u pixels of size
*/
#define BLOCK 1

// TYPEDEFS --------------------------------------------------------------------

// RGB 8bit
typedef struct
{
	union
  { // red, green, blue
    i8 r,g,b;	 // component styles
    i8 rgb[3]; // array style
	};
} ColorRGB8;

/* callback for framebuffer processing:
   called with current [x,y], current color pointer -> depends on ProcessingType
   -> Vector4 represents RGBA (x=red,y=green,z=blue,w=alpha)
*/
typedef void (*FramebufferCallback)(ui32 x, ui32 y, Vector4 *c);

/* framebuffer pixels are ordered in the range of ([0,x-1], [0,y-1]).
   coordinate (0,0) is the top left corner.
*/
typedef struct
{
	Vector4 *buffer;        // memory location of the framebuffer data
	ui32 width, height;	    // width,height in pixels X,Y
	FramebufferCallback cb; // callback function used in FramebufferProcess()
} Framebuffer;

// FUNCTIONS -------------------------------------------------------------------

void FramebufferInit();                                       // clear all memory and reset framebuffer engine

i32  FramebufferCreate  (ui32 width, ui32 height);            // create a framebuffer held in memory -> RETURNS CREATED SLOT NUMBER
void FramebufferRegister(ui32 slot, FramebufferCallback cb);  // register a function callback for FramebufferProcess() to work with
void FramebufferProcess (ui32 slot, ui32 ProcessingType);     // process the framebuffer and call a registered callback
void FramebufferClear   (ui32 slot, Vector4 *c);              // clear framebuffer to color X -> Vector4 represents RGBA (x=red,y=green,z=blue,w=alpha)
void FramebufferWrite   (ui32 slot, fp gamma, ui8 *filename); // write framebuffer to disk as RGB8 PPM

Framebuffer* FramebufferGetRaw (ui32 slot);                   // retrieve raw access to a framebuffer that was previously created

#endif // _FRAMEBUFFER
